import sys
import Utils.utilities
from Utils.BeautifulSoup import *
#from Utils.XbmcHandler import XbmcHandler

print "From context menu"
print sys.argv

args = sys.argv[1].split(" ")
baseUrl = args[0]
action = args[1]
pluginMode = args[2]
userName = args[3]
password = args[4]
videoId = args[5]
if(len(args) == 7):
    seriesId = args[6]

pluginModeValue = pluginMode.split("=")[1]
url = ""

#xbmcHandler = XbmcHandler()
if(pluginModeValue == "2"):
    url = "%s/PluginService.aspx?%s&%s&%s&%s&%s&action=%s" % (baseUrl.replace("/default.aspx", ""), pluginMode, userName, password, videoId, seriesId, action)
    
elif(pluginModeValue == "1"):
    url = "%s/PluginService.aspx?%s&%s&%s&%s&action=%s" % (baseUrl.replace("/default.aspx", ""), pluginMode, userName, password, videoId, action)
else:
    print "unknown mode"    

print "contextMenu url: %s" % url    
if(url != ""):    
    source = Utils.utilities.ReadUrlPageData(url)

if(action == "Remove"):
    try:
        import xbmc
        xbmc.executebuiltin('XBMC.Container.Refresh()')
        print "Run executebuiltin"
    except:
        print "Failed to executebuiltin"
    
#Container.Refresh
#Container.Update
#soup = BeautifulStoneSoup(source)
#itemsTag = soup.findAll('item')
#if(len(itemsTag) == 0):
#    xbmcHandler.ShowMessageBox("Operation Result", "No Items Found")

#elif(itemsTag[0].title.string != "Item Added"):
#    xbmcHandler.ShowMessageBox("Adding item failed", itemsTag[0].description.string)
#else:
    #xbmcHandler.ShowMessageBox("Item Added", "")